interface IUser {
  name: string;
  age: number;
  sayHello(this: IUser): void;
}

// 在对象字面量（如果没有其他限制）中this默认为any类型
const u: IUser = {
  name: "zs",
  age: 33,
  sayHello() {
    console.log(this.age, this.name);
  },
};

const sayHello = u.sayHello();
// sayHello()

// 在类中明确指定this为当前实例对象
class User {
  constructor(public name: string, public age: number) {}

  sayHello(this: User) {
    console.log(this.name, this.age);
  }
}
